<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'home';
$return['ischecklogin']=cfc('core')->checklogin('','',true);
$this->model('member')->upmember();
$return['pluginset']['ailogo']=tomedia($return['pluginset']['ailogo']);
$return['basic']=$return['pluginset'];
if($_RQ['op']=='home'){
	$_SESSION['checkimg']=1;
	if($_RQ['id']){
		$return['post']=pdo_get('jy_agentmcp_usergoods',array('id'=>$_RQ['id'],'uniacid'=>$_SESSION['uniacid']));
		$return['post']['oldlogo']=$return['post']['logo'];
		$return['post']['logo']=tomedia($return['post']['logo']);
	}else{
		$return['post']=array('ainame'=>'小云','llm_model'=>'qwen','llm_model2'=>0,'desc'=>$return['demo']['desc']);
	}
	$return['post']['goodsid']=intval($_RQ['goodsid']);
	foreach($return['pluginset']['logoimgs'] as &$img){
		$img=tomedia($img);
	}
	$return['params']=array('groupid'=>0,'voicesex'=>0,'yuyuantype'=>0);
	$return['sharedata']=array(
		'title'=>$return['basic']['share_title'],
		'desc'=>$return['basic']['share_desc'],
		'link'=>custom_url('jy_agentmcp/index//fromuser='.$_SESSION['uid'],true),
		'imgUrl'=>ATTACHMENT_URL.$return['basic']['share_image'],
	);
	set_html('title','编辑智能体MCP');
	exi($return);
}
if($_RQ['op']=='post'){
		$postdata=get_postdata();
		if(!$postdata['title']){
			exi('请填写名称！','error');
		}
		if(!$postdata['mcpurl']){
			exi('请输入MCP接入点！','error');
		}
		if (isset($postdata['mcpurl']) && strpos($postdata['mcpurl'], 'wss://') === 0) {
		} else {
			exi('请输入正确MCP接入点！必须是：wss://开头！','error');
		}
		if($_SESSION['wxapp_id'] && $_SESSION['container']=='wxapp'){
			$result=model('core/wxapp_api')->msgSecCheck($postdata['title']);
			if($result['errcode']){
				exi('标题内容可能不合法！','error');
			}
			if($postdata['mcpurl']){
				$result=model('core/wxapp_api')->msgSecCheck($postdata['mcpurl']);
				if($result['errcode']){
					exi('MCP接入点内容可能不合法！','error');
				}
			}
		}
		$id=$this->model('agent')->addusergoods($postdata);
		exi($id);		
}